interface Config {
    tableBg: string,
    tableColor: string
};

export const getEmailContent = (data: any, list: any, transportTypes: string[], config: Config) => {
    const border = 'style="border: 1px solid #333; padding: 6px 0px"';
    // 所有数量行数据开始
    const numTrs: string[] = []
    const dayObj: any = {} // 交期数据
    list.forEach((item: any) => {
        const str = `
            <tr>
                <td ${border}>${item.count}</td>
                ${item.itemList.map((obj: any) => `<td ${border}>${obj.netPrice}</td>`).join('')}
            </tr>
        `
        numTrs.push(str)

        item.itemList.forEach((e: { transportTypes: string | number; delivery: any; }) => {
            if (!dayObj[e.transportTypes]) {
                dayObj[e.transportTypes] = []
            }
            dayObj[e.transportTypes].push(e.delivery);
        });
    })
    // 所有数量行数据结束

    // 交期数据处理
    const dayTrs = []
    for (let index in dayObj) {
        const days = dayObj[index].map((val: string) => {
            return Number(val.replace(/[^0-9]/ig, ""))
        })
        const min = Math.min(...days);
        const max = Math.max(...days);
        if (min === max) {
            dayTrs.push(`<td ${border}>${min} Days</td>`)
        } else {
            dayTrs.push(`<td ${border}>${min}-${max} Days</td>`)
        }
    }
    const tableStr = `
        <table border="1" style="color: ${config.tableColor}; background-color: ${config.tableBg}; width: 600px;text-align:center;border-collapse: collapse; ">
            <tr>
                <td ${border}>QTY</td>
                ${transportTypes.map(type => `<td ${border}>Net Price By ${type}</td>`).join('')}
            </tr>
            ${numTrs.join('')}
            <tr>
                <td ${border}>In Hand Time</td>
                ${dayTrs.join('')}
            </tr>
        <table>
    `

    const content = `
        <div style="line-height: 22px;">
            <div>Thank you for your inquiry regarding ${data.productCode ? `#${data.productCode} ` : ''}${data.productName}. We appreciate the opportunity to assist you and are happy to provide the information you need.</div>
            <div style="margin-top: 10px;">- Item: ${data.productCode ? `#${data.productCode} ` : ''}${data.productName}</div>
            <div>- Material: ${data.material}</div>
            <div>- Available Color: ${data.customColor}</div>
            <div>- Size: ${data.productSize} ${data.sizeUnit}</div>
            <div>- Imprint: ${data.printWay}, ${data.printLogo}</div>
            <div>- Packaging: ${data.packaging}</div>
            <div>- SetupCharge: $${data.setupCharge}</div>
            <div>- Net price (Door to door price.included shipping):</div>
            ${tableStr}
            <div>- Lead time: Production time + Transit time</div>
        </div>
    `;
    return content;
};